def f(a):
    if a%2==0:
        return a==2
    b=3
    while b*b<=a and a%b!=0:
        b+=2
    return b*b>a
     
n=input() 
p=[] 
for i in range(len(n)+1): 
    for k in range(i,len(n)+1): 
        if i==k: 
            continue 
        a=int(n[i:k]) 
        if f(a): 
            p+=[a] 
print(max(p) if p else 0)
